﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;


namespace FileOp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private string fileName = "file.txt";

        private void button1_Click(object sender, EventArgs e)
        {
            FileInfo fileInfo = new FileInfo(fileName);
            if (fileInfo.Exists == false)
            {
                using (StreamWriter sw = fileInfo.CreateText())
                {
                    sw.WriteLine("123");
                    sw.Flush();
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate);
            fs.Seek(1, SeekOrigin.Current);
            byte[] bytes = new UTF8Encoding().GetBytes("4");
            fs.WriteByte(bytes[0]);
            fs.Flush();
        }
    }
}
